package com.zb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.ZjFactoryRole;
import com.zb.mapper.ZjFactoryRoleMapper;
import com.zb.service.ZjFactoryRoleService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 厂商角色表 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2024-02-27
 */
@Service
public class ZjFactoryRoleServiceImpl extends ServiceImpl<ZjFactoryRoleMapper, ZjFactoryRole> implements ZjFactoryRoleService {

    // 保存品牌商家超级管理员角色
    @Override
    public Long saveFactoryAdmin(Long factoryId) {
        QueryWrapper<ZjFactoryRole> wrapper = new QueryWrapper<>();
        wrapper.select("id")
                .eq("factory_id", factoryId)
                .eq("is_admin", 1);
        ZjFactoryRole role = this.getOne(wrapper);
        if (null != role) {
            return role.getId();
        }
        role = new ZjFactoryRole();
        role.setId(IdWorker.getId());
        role.setFactoryId(factoryId);
        role.setCode("super_admin");
        role.setName("系统超管");
        role.setAdmin(true);
        role.setDisabled(false);
        this.save(role);
        return role.getId();
    }
}
